var BaseNode = require('./../../FrameWork/Component/BaseNode');
cc.Class({
    extends: BaseNode,

    properties: {
        lbScore: {
            default: null,
            type: cc.Label,
            displayName: '分数节点'
        },
        isShowAdd: {
            default: false,
            displayName: '是否显示加号'
        },
    },
    /**开始播放滚动动画*/
    playRollAnim(_startNmber, _endNumber) {
        let actArray = [];
        let tmpNumber = _endNumber - _startNmber;
        let cnt = 30;
        actArray.push(cc.delayTime(1));
        this.setScale(0);
        actArray.push(cc.callFunc(function() {
            this.setScale(1);
        }.bind(this)));
        for (let i = 0; i < cnt; ++i) {
            let _showScore = i / cnt * tmpNumber + _startNmber;
            _showScore = Math.floor(_showScore);
            actArray.push(cc.callFunc(function() {
                this.refreshScore(_showScore);
            }.bind(this)));
            actArray.push(cc.delayTime(0.01));
        }
        actArray.push(cc.callFunc(function() {
            this.refreshScore(_endNumber)
        }.bind(this)));
        this.doSequenceAnim(actArray);
    },

    /**开始播放滚动动画*/
    play(_startNmber, _endNumber) {
        let actArray = [];
        let tmpNumber = _endNumber - _startNmber;
        let cnt = 30;
        for (let i = 0; i < cnt; ++i) {
            let _showScore = i / cnt * tmpNumber + _startNmber;
            _showScore = Math.floor(_showScore);
            actArray.push(cc.callFunc(function() {
                this.refreshScore(_showScore);
            }.bind(this)));
            actArray.push(cc.delayTime(0.01));
        }
        actArray.push(cc.callFunc(function() {
            this.refreshScore(_endNumber)
        }.bind(this)));
        this.doSequenceAnim(actArray);
    },

    refreshScore(_score) {
        this.lbScore.string = _score.toString();
        if (this.isShowAdd && _score > 0) {
            this.lbScore.string = '+' + _score.toString();
        }
    }
});